package slh.favourite;

import slh.Book.Book;
import slh.Book.BookDao;
import slh.movie.Movie;
import slh.movie.MovieDao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class FavouriteService {
    private FavouriteDao favoriteDAO;
    private MovieDao movieDAO;
    private BookDao bookDAO;

    public   FavouriteService(Connection conn) {
        this.favoriteDAO = new FavouriteDao(conn);
        this.movieDAO = new MovieDao(conn);
        this.bookDAO = new BookDao(conn);
    }

    // 添加收藏
    public boolean addFavorite(String userId, int contentId, String contentType) throws SQLException {
        return favoriteDAO.addFavorite(userId, contentId, contentType);
    }

    // 取消收藏
    public boolean removeFavorite(String userId, int contentId, String contentType) throws SQLException {
        return favoriteDAO.removeFavorite(userId, contentId, contentType);
    }

    // 检查是否已收藏
    public boolean isFavorite(String userId, int contentId, String contentType) throws SQLException {
        return favoriteDAO.isFavorite(userId, contentId, contentType);
    }

    // 获取用户收藏的电影列表
    public List<Movie> getUserFavoriteMovies(String userId) throws SQLException {
        List<Integer> movieIds = favoriteDAO.getUserFavorites(userId, "movie");
        return movieDAO.getMoviesByIds(movieIds);
    }

    // 获取用户收藏的图书列表
    public List<Book> getUserFavoriteBooks(String userId) throws SQLException {
        List<Integer> bookIds = favoriteDAO.getUserFavorites(userId, "book");
        return bookDAO.getBooksByIds(bookIds);
    }
}